﻿// //------------------------------------------------------------------------------
// // <copyright file="" company="Dascoba Development">
// //  Copyright © Dascoba Development 2010
// // </copyright>
// //------------------------------------------------------------------------------
using umbraco.BasePages;

namespace Dascoba.Umb.FileManager.Actions
{
    using Dascoba.Umb.FileManager.Support;

    using umbraco.interfaces;

    public class ActionCreateFolder : IAction
    {
        /// <summary>
        ///   Initializes a new instance of the <see cref = "ActionCreateFolder" /> class.
        /// </summary>
        private ActionCreateFolder()
        {
        }

        /// <summary>
        ///   Gets the instance.
        /// </summary>
        /// <value>The instance.</value>
        public static ActionCreateFolder Instance
        {
            get
            {
                // return singleton
                return new ActionCreateFolder();
            }
        }

        #region Implementation of IAction

        /// <summary>
        ///   Gets the letter.
        /// </summary>
        /// <value>The letter.</value>
        public char Letter
        {
            get
            {
                // U+0188: Latin Capital Letter D With Topbar
                return 'Ƌ';
            }
        }

        /// <summary>
        ///   Gets a value indicating whether [show in notifier].
        /// </summary>
        /// <value><c>true</c> if [show in notifier]; otherwise, <c>false</c>.</value>
        public bool ShowInNotifier
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        ///   Gets a value indicating whether this instance can be permission assigned.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance can be permission assigned; otherwise, <c>false</c>.
        /// </value>
        public bool CanBePermissionAssigned
        {
            get
            {
                return true;
            }
        }

        /// <summary>
        ///   Gets the icon.
        /// </summary>
        /// <value>The icon.</value>
        public string Icon
        {
            get
            {
                return string.Format("/../../{0}/images/newfolder.png", Constants.FileManagerFolderName);
            }
        }

        /// <summary>
        ///   Gets the alias.
        /// </summary>
        /// <value>The alias.</value>
        public string Alias
        {
            get
            {
                return "createFolder";
            }
        }

        /// <summary>
        ///   Gets the name of the js function.
        /// </summary>
        /// <value>The name of the js function.</value>
        public string JsFunctionName
        {
            get
            {
                if (Util.SupportsJQueryTree)
                {
                    return "CreateFolder('" + umbraco.ui.Text("actions", this.Alias) + "')";
                }

                return "parent.CreateFolder('" + umbraco.ui.Text("actions", this.Alias) + "')";
            }
        }

        /// <summary>
        ///   Gets the js source.
        /// </summary>
        /// <value>The js source.</value>
        public string JsSource
        {
            get
            {
                if (Util.SupportsJQueryTree)
                {
                    return
                        @"
                        function CreateFolder(title) {
                            if (nodeID != '-1' && nodeType != '') {

                                UmbClientMgr.openModalWindow('~/umbraco/filemanager/Dialogs/CreateFolder.aspx?folder=' + encodeURI(nodeID), title, 155, 425);
                                return false;
                            }
                        }    ";
                }

                return string.Format("{0}/js/createFolder.js", Constants.FileManagerGlobalUrl);
            }
        }

        #endregion
    }
}